export const format = (date, format = "YYYY-MM-DD") => {
    // 如果没有传入日期，使用当前日期
    const d = date ? new Date(date) : new Date();

    // 获取年月日时分秒
    const year = d.getFullYear();
    const month = d.getMonth() + 1;
    const day = d.getDate();
    const hour = d.getHours();
    const minute = d.getMinutes();
    const second = d.getSeconds();

    // 补零函数
    const pad = (n) => n.toString().padStart(2, '0');

    // 替换格式字符串
    return format
        .replace('YYYY', year)
        .replace('MM', pad(month))
        .replace('DD', pad(day))
        .replace('HH', pad(hour))
        .replace('mm', pad(minute))
        .replace('ss', pad(second));
};

export const isBefore = (date1, date2) => {
    return new Date(date1) < new Date(date2)
}

export const isAfter = (date1, date2) => {
    return new Date(date1) > new Date(date2)
}

export const isSameDay = (date1, date2) => {
    return format(date1) === format(date2)
}
export const isSameBeforeDay = (date1, date2) => {
    return isBefore(date1, date2) || isSameDay(date1, date2)
}
export const isSameAfterDay = (date1, date2) => {
    return isAfter(date1, date2) || isSameDay(date1, date2)
}

